import { OrderStockInterfaceWithDerive, OrderStockGateway, getOrderStockStatMonthDto, NotchQueryCache, ExtIdTuple } from "qqlx-core";

import { ViewBase } from "@view/view-base";

type OrderStockViewSchema = NotchQueryCache & Omit<ExtIdTuple, "id">;

export class ViewOrderStock extends ViewBase<OrderStockViewSchema> implements OrderStockInterfaceWithDerive<{}> {
  private static instance: ViewOrderStock;
  static getInstance(options?: { isSingleton?: boolean }) {
    if (options?.isSingleton === false) {
      return new ViewOrderStock();
    }

    if (!this.instance) this.instance = new ViewOrderStock();
    return this.instance;
  }

  private constructor() {
    super();
    this.initial();
    this.insertDefaultCondition();
  }

  async getOrderStockStatMonth(dto: getOrderStockStatMonthDto) {
    const path = `${OrderStockGateway.path}/stat/month`;
    return this.$request.getByPut<getOrderStockStatMonthDto, NotchQueryCache>(path, dto);
  }
}
